﻿using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UMLSynthesizer.CSharpAnalyzer.Elements;
using UMLSynthesizer.LangAnalyzer.Elements;
using UMLSynthesizer.LangAnalyzer.Expressions;
using UMLSynthesizer.LangAnalyzer.Statements;

namespace UMLSynthesizer.CSharpAnalyzer.Expressions
{
    class CSharpGenericExpression : CSharpExpressionBase, IGenericExpression
    {
        #region Constructor

        public CSharpGenericExpression(ExpressionSyntax expressionNode,
            IExpressionBase parentExpression,
            IStatementBase parentStatement)
            : base(expressionNode, parentExpression, parentStatement, ExpressionKinds.Generic) { }

        #endregion

        #region Properties

        public IEnumerable<ITypeBase> ReferredTypes
        {
            get
            {
                return (from node in expressionNode.DescendantNodesAndSelf()
                        where node as TypeSyntax != null
                        let typeReference = (ProjectOwner as CSharpProjectElement).GetTypeReference(node as TypeSyntax)
                        where typeReference != null
                        select typeReference).Distinct();
            }
        }

        #endregion
    }
}
